using System;

namespace BankSimulation
{
    public class ATM : ICashMachine
    {
        public event EventHandler<BigMoneyArgs>? BigMoneyFetched;

        public void Withdraw(Account account, decimal amount)
        {
            Random rand = new Random();
            if (rand.NextDouble() < 0.3)
                throw new BadCashException("检测到破损钞票");

            account.Withdraw(amount);

            if (amount > 10000)
                OnBigMoneyFetched(new BigMoneyArgs { Account = account, Amount = amount });
        }

        protected virtual void OnBigMoneyFetched(BigMoneyArgs e)
        {
            BigMoneyFetched?.Invoke(this, e);
        }
    }
}